# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=libgsf
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.14.50
pkgrel=2
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
pkgdesc="An extensible I/O abstraction library for dealing with structured file formats (mingw-w64)"
depends=("${MINGW_PACKAGE_PREFIX}-bzip2"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-vala"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc")
license=('spdx:LGPL-2.1-only')
url="https://gitlab.gnome.org/GNOME/libgsf.git"
source=(https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz
        002-get-unix-path-for-git.patch
        https://gitlab.gnome.org/GNOME/libgsf/-/commit/167d7f96c81683392933ddb8c427e5d7c8ce284d.patch)
sha256sums=('6e6c20d0778339069d583c0d63759d297e817ea10d0d897ebbe965f16e2e8e52'
            'f08db8333d2b4a369737a77969b5896d408a4d9992fab6f1c9c44ddeae25c516'
            '1db394176d0f6a98c2ad32a9cdaf05a183ae07c972f60153ff5160cb88ee2660')

prepare() {
  cd ${_realname}-${pkgver}
  patch -b -V simple -p1 -i ${srcdir}/002-get-unix-path-for-git.patch
  patch -p1 -i "${srcdir}/167d7f96c81683392933ddb8c427e5d7c8ce284d.patch"

  autoreconf -fiv
}

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  mkdir -p doc/html
  cp -rf ../${_realname}-${pkgver}/doc/html/* doc/html

  ../${_realname}-${pkgver}/configure \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --libexecdir=${MINGW_PREFIX}/lib \
    --enable-introspection \
    --disable-gtk-doc

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING.LIB" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.LIB"
}
